<?
header("Content-type: text/html; charset=utf-8");
//�ж���ݿ�����
if (!class_exists("go_sql")) {
    include("/var/www/html/new/conf/le.je");
    $le = new go_sql();
    $le->connect();
}
$ac = '16ucom';
$pw = 'c33367701511b4f6020ec61ded352059';
$inSide = new SoapClient(null, array("location" => "http://localhost/open/openService/pft_insideMX.php", "uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$txt='TUQ4OSM1YzVhYjViNWQ1MGRmMDgzOTAzYzQ3NTZkOGJmYTZmNHxbeyJpZCI6IjQyMzc5Iiwib3JkZXJpZCI6IjE1NTEwMzkiLCJwcmVfbnVtIjoiMSIsImRvbmVfbnVtIjoiMCIsInJlY3RpbWUiOiIyMDE1LTA3LTIxIDA5OjU2OjM1In1d';
//$txt = 'VEs3OSM0NWY3NTU2ZjU0NzhhZDllZDc5OGI5ODE2MWE5MTY1N3xbeyJpZCI6IjE0NTI0MTYiLCJvcmRlcmlkIjoiMTU1MjQxNCIsInBheV9zdGF0dXMiOiIxIn1d';
$retime1 = microtime(true);
$arr = base64_decode($txt);
print_r($arr);
exit;
$arrs1 = explode('#', $arr);
$arrs2 = explode('|', $arrs1[1]);
$method = $arrs1[0];
$Check = $arrs2[0];
$order_arr = json_decode($arrs2[1], true);//������š������š�֧��״̬
$order_arr_id = $order_arr[0]['id'];
$order = $order_arr[0]['orderid'];//Ʊ��ͨ������
$methoda = substr($arr, 0, 5);
$sign = md5(($order_arr_id + $order) . $methoda);
if ($Check == $sign) {
    foreach ($order_arr as $orders) {
//        $order_true = $orders['orderid']; //Ʊ��ͨ������
        $order_true = 1552414;
        $pft_order = $inSide->Order_Globle_Search(
            0, 0, 0, 0, "",
            "", "", "", "", "",
            "", "", $order_true, "", 0,
            "", "", "", 1, 0,
            0, 1, "", "", "",
            "", "", "", "", "",
            "", "", "1", "", "");
        $pft_order_xml = simplexml_load_string($pft_order);
print_r($pft_order);
        exit;
        $UUlid = (int)$pft_order_xml->Rec->UUlid; //����id
        $UUtid = (int)$pft_order_xml->Rec->UUtid; //��Ʊid
        $UUltitle = (string)$pft_order_xml->Rec->UUltitle; //�������
        $UUttitle = (string)$pft_order_xml->Rec->UUttitle; //��Ʊ���
        $ordername = (string)$pft_order_xml->Rec->UUordername; //������������
        $UUtnum = (int)$pft_order_xml->Rec->UUtnum; //��������
        $UUremotenums = explode("_", (string)$pft_order_xml->Rec->UUremotenum);
        $UUremotenum = $UUremotenums[1];//Զ�˶�����
        $UUpid = (int)$pft_order_xml->Rec->UUpid; //��Ʊpid
        $UUordertime = (string)$pft_order_xml->Rec->UUordertime; //�µ�ʱ��
        $UUplaytime = (string)$pft_order_xml->Rec->UUbegintime; //����ʱ��
        $UUendtime = (string)$pft_order_xml->Rec->UUendtime; //����ʱ��
        $UUtprice = (string)$pft_order_xml->Rec->UUtprice; //�����
        $UUordertel = (string)$pft_order_xml->Rec->UUordertel; //���������ֻ����
        $UUstatus = (int)$pft_order_xml->Rec->UUstatus; //����״̬
        $IDcar = (string)$pft_order_xml->Rec->UUpersonid; //�����������֤��
        $UUcode = (string)$pft_order_xml->Rec->UUcode; //ƾ֤��
        $UUpmode = (string)$pft_order_xml->Rec->UUpmode;//֧����ʽ
        $UUmid = (string)$pft_order_xml->Rec->UUmid;//��Ӧ��ID
        $select_uuid = "select uuid from uu_jq_ticket where id=" . $UUtid . " limit 1";
        $GLOBALS['le']->query($select_uuid);
        $GLOBALS['le']->fetch_assoc();
        $uuid = $GLOBALS['le']->f('uuid'); //��ѯ��Ʒ����id

        $UUlprice = $inSide->get_Dynamic_Price_Merge(
            $UUpid, $UUplaytime, 1, '', '', 1, 0
        ); //���ۼ�

        $retime2 = microtime(true);
        /*method��TK79-���Ͷ���,MD89-�޸Ķ���,ȡ��*/
        if ($method == 'TK79') {
            $pay_status = $orders['pay_status']; //0δ֧����1��֧��
            $request_array = array(
                'pftordernum' => $order_true,
                'pftordername' => $ordername,
                'UUtnum' => $UUtnum,
                'UUordertime' => $UUordertime,
                'UUplaytime' => $UUplaytime,
                'UUendtime' => $UUendtime,
                'UUtprice' => $UUtprice / 100,
                'UUordertel' => $UUordertel,
                'uuid' => $uuid,
                'IDcar' => $IDcar,
                'productname' => $UUttitle,
                'UUltitle' => $UUltitle,
                'UUcode' => $UUcode,
                'UUlprice' => $UUlprice / 100,
                'ispay' => $pay_status,
                'pmode'=>$UUpmode,
                'UUmid'=>$UUmid,
            );

            switch ($UUlid) {
                case 9568://��ɽ


                    include_once '/var/www/html/new/d/module/qkxproject/api/longhushan/LongHuShan.class.php';
                    $longhushan = new LongHuShan();


                    $request = $longhushan->PFT_Order_Submit($request_array);


                    if($request == 101){
                        echo 101;
                    }
                    else{
                        $updateRemote = $inSide->Remote_Ordernum_Update(
                            serialize(array($order_true=>'longhushan_'.$request))
                        );

                        $str = "update uu_order_fx_details set memo='lhs_success' where orderid=".$order_true." limit 1";
                         echo $str;
                        $GLOBALS['le']->query($str);
                        echo 100;
                    }

                    break;

                default:
                    break;
            }

        } elseif ($method == 'MD89') { //�޸�andȡ��
            $pre_num = $orders['pre_num']; //ԭʼ��������
            $done_num = $orders['done_num']; //�޸ĺ�����,0ȡ��
            $rectime = $orders['rectime']; //����ʱ��
            switch ($UUlid) {
                case 9568://��ɽ
                    include '/var/www/html/new/d/module/qkxproject/api/longhushan/LongHuShan.class.php';
                    $longhushan = new LongHuShan();

                    $longhushan_orderid = $longhushan->Order_Globle_Search($UUremotenum);//��ȡ��ɽ������
                    $arr_refund = array(
                        'pre_num' =>$pre_num,//ԭʼ��������
                        'done_num' => $orders['done_num'], //�޸ĺ�����,0ȡ��
                        'rectime' => $orders['rectime'],//����ʱ��
                        'longhushan_orderid'=>(int)$longhushan_orderid,//��ɽ������
                        'tel'=>'1234567890'//Ԥ���޸��ֻ����
                    );

                    $select_Onum = $longhushan->Order_Change_Pro($arr_refund);//Զ�˶�����

                    break;

                default:
                    break;

            }
        }
    }
}
//���ص�ǰ Unix ʱ�����΢����
$retime5 = microtime(true);
$retime6 = $retime5 - $retime1;
$log = logfile(date('Y-m-d H:i:s') . ' runtime6:' . $retime6, '/var/www/html/new/d/module/qkxproject/api/longhushan/longhushan_log.txt');


function logfile($txt, $path)
{
    $fp = fopen($path, "a");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}

?>